package com.guigu.lc.controller.sys;

import com.guigu.common.pojo.SysRoles;
import com.guigu.common.pojo.SysUsers;
import com.guigu.lc.serach.MenusSerach;
import com.guigu.lc.serach.RolesSerach;
import com.guigu.lc.service.sys_RoleService;
import com.guigu.lc.view.RoleandMenuview;
import com.guigu.lc.view.Roleview;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@RequestMapping("/sys")
@ResponseBody()
public class RolesController {

    @Resource
    private sys_RoleService sysRoleService;

    //查询所有角色
    @RequestMapping("/queryallrolesys")
    public RolesSerach queryallrolesys(RolesSerach rolesSerach){
        return this.sysRoleService.queryallrolesyService(rolesSerach);
    }

    //角色授予或收回菜单查询
    @RequestMapping("/querygrentrolemenus")
    public MenusSerach querygrentrolemenus(MenusSerach menusSerach){
        Subject subject = SecurityUtils.getSubject();
        SysUsers user1 = (SysUsers) subject.getSession().getAttribute("user");
        menusSerach.setUserid(user1.getId());
    return this.sysRoleService.querygrentrolemenusService(menusSerach);
    }
    //查询选中的角色有的菜单编号
    @RequestMapping("/targtentid")
    public RoleandMenuview targtentid(int id){
        return this.sysRoleService.targtentidService(id);
    }

    //授权收回角色菜单选择不为kong
    @RequestMapping("/grentshouhuirolemenus1")
    public int grentshouhuirolemenus1(@RequestBody() RoleandMenuview roleandMenuview){
         this.sysRoleService.grentshouhuirolemenus(roleandMenuview);
        return 1;
    }

    //授权收回角色菜单选择为空
    @RequestMapping("/grentshouhuirolemenus2")
    public int grentshouhuirolemenus2(@RequestBody() RoleandMenuview roleandMenuview){
        this.sysRoleService.grentshouhuirolemenus2(roleandMenuview);
        return 1;
    }

    //注册角色
    @RequestMapping("/inserttroleadddzc")
    public int inserttroleadddzc(SysRoles roles){
        Subject subject = SecurityUtils.getSubject();
        SysUsers user1 = (SysUsers) subject.getSession().getAttribute("user");
        Roleview v=new Roleview();
        v.setRoles(roles);
        v.setUserid(user1.getId());
        this.sysRoleService.insertaddandupdateroleuserService(v);
        return 1;
    }
}
